using MicroMsg.Network;
using MicroMsg.Resource.@string;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.Page
{
	public class NetFlowPage : BasePage
	{
		private const double baseY = 53.0;
		private const double stackPanelHeight = 69.0;
		private List<TextBlock> listDate = new List<TextBlock>();
		private List<TextBlock> listCell = new List<TextBlock>();
		private List<TextBlock> listWifi = new List<TextBlock>();
		private List<StackPanel> listStack = new List<StackPanel>();
		private ApplicationBar mBar;
		private ApplicationBarMenuItem clearHistoryButton;
		internal Grid LayoutRoot;
		internal Grid ContentPanel;
		internal TextBlock TxtTotalSum;
		internal TextBlock Txt3G2GAll;
		internal TextBlock TxtWifiAll;
		internal StackPanel stackPanel0;
		internal TextBlock TxtTimeData0;
		internal TextBlock Txt3G2GData0;
		internal TextBlock TxtWifiData0;
		internal StackPanel stackPanel1;
		internal TextBlock TxtTimeData1;
		internal TextBlock Txt3G2GData1;
		internal TextBlock TxtWifiData1;
		internal StackPanel stackPanel2;
		internal TextBlock TxtTimeData2;
		internal TextBlock Txt3G2GData2;
		internal TextBlock TxtWifiData2;
		internal StackPanel stackPanel3;
		internal TextBlock TxtTimeData3;
		internal TextBlock Txt3G2GData3;
		internal TextBlock TxtWifiData3;
		internal StackPanel stackPanel4;
		internal TextBlock TxtTimeData4;
		internal TextBlock Txt3G2GData4;
		internal TextBlock TxtWifiData4;
		internal StackPanel stackPanel5;
		internal TextBlock TxtTimeData5;
		internal TextBlock Txt3G2GData5;
		internal TextBlock TxtWifiData5;
		internal StackPanel stackPanel6;
		internal TextBlock TxtTimeData6;
		internal TextBlock Txt3G2GData6;
		internal TextBlock TxtWifiData6;
		internal StackPanel YearLine;
		internal TextBlock TxtYear;
		private bool _contentLoaded;
		public NetFlowPage()
		{
			this.InitializeComponent();
		}
		protected override void OnPageIn(object[] object_0)
		{
			this.InitData();
			this.RefreshUI();
			base.set_ApplicationBar(this.getApplicationBar());
		}
		protected override void OnPageOut()
		{
		}
		private void InitData()
		{
			this.listDate.Add(this.TxtTimeData0);
			this.listDate.Add(this.TxtTimeData1);
			this.listDate.Add(this.TxtTimeData2);
			this.listDate.Add(this.TxtTimeData3);
			this.listDate.Add(this.TxtTimeData4);
			this.listDate.Add(this.TxtTimeData5);
			this.listDate.Add(this.TxtTimeData6);
			this.listCell.Add(this.Txt3G2GData0);
			this.listCell.Add(this.Txt3G2GData1);
			this.listCell.Add(this.Txt3G2GData2);
			this.listCell.Add(this.Txt3G2GData3);
			this.listCell.Add(this.Txt3G2GData4);
			this.listCell.Add(this.Txt3G2GData5);
			this.listCell.Add(this.Txt3G2GData6);
			this.listWifi.Add(this.TxtWifiData0);
			this.listWifi.Add(this.TxtWifiData1);
			this.listWifi.Add(this.TxtWifiData2);
			this.listWifi.Add(this.TxtWifiData3);
			this.listWifi.Add(this.TxtWifiData4);
			this.listWifi.Add(this.TxtWifiData5);
			this.listWifi.Add(this.TxtWifiData6);
			this.listStack.Add(this.stackPanel0);
			this.listStack.Add(this.stackPanel1);
			this.listStack.Add(this.stackPanel2);
			this.listStack.Add(this.stackPanel3);
			this.listStack.Add(this.stackPanel4);
			this.listStack.Add(this.stackPanel5);
			this.listStack.Add(this.stackPanel6);
		}
		private void RefreshUI()
		{
			DateTime dateTime = DateTime.get_Now().ToLocalTime();
			int year = dateTime.get_Year();
			NetStreamItem totalNetStream = FlowControl.getTotalNetStream();
			if (!R.isChineseCN() && !R.isChineseTW())
			{
				this.TxtTotalSum.set_Text("From\n" + totalNetStream.startDate.ToString("yyyy-MM-dd"));
			}
			else
			{
				this.TxtTotalSum.set_Text(totalNetStream.startDate.ToString("yyyy-MM-dd") + "\n至今");
			}
			if (totalNetStream != null)
			{
				uint totalStreamCell = totalNetStream.totalStreamCell;
				uint totalStreamWifi = totalNetStream.totalStreamWifi;
				if (totalStreamCell >= 1048576u)
				{
					this.Txt3G2GAll.set_Text(Math.Round(totalStreamCell / 1048576.0, 2).ToString() + "M");
				}
				else
				{
					this.Txt3G2GAll.set_Text(Math.Round(totalStreamCell / 1024.0).ToString() + "KB");
				}
				if (totalStreamWifi >= 1048576u)
				{
					this.TxtWifiAll.set_Text(Math.Round(totalStreamWifi / 1048576.0, 2).ToString() + "M");
				}
				else
				{
					this.TxtWifiAll.set_Text(Math.Round(totalStreamWifi / 1024.0).ToString() + "KB");
				}
			}
			else
			{
				this.Txt3G2GAll.set_Text("0KB");
				this.TxtWifiAll.set_Text("0KB");
			}
			for (int i = 0; i < 7; i++)
			{
				DateTime dateTime2 = dateTime.AddDays((double)(-(double)i));
				if (dateTime2 < totalNetStream.startDate)
				{
					IL_37F:
					while (i < 7)
					{
						this.listStack.get_Item(i).set_Visibility(1);
						i++;
					}
					return;
				}
				if (dateTime2.get_Year() != year)
				{
					this.ShowYearLine(i, year);
				}
				year = dateTime2.get_Year();
				NetStreamItem netStreamByDayOffset = FlowControl.getNetStreamByDayOffset(-i);
				if (netStreamByDayOffset != null)
				{
					this.listDate.get_Item(i).set_Text(dateTime2.ToString("yyyy-MM-dd"));
					uint totalStreamCell2 = netStreamByDayOffset.totalStreamCell;
					uint totalStreamWifi2 = netStreamByDayOffset.totalStreamWifi;
					if (totalStreamCell2 >= 1048576u)
					{
						this.listCell.get_Item(i).set_Text(Math.Round(totalStreamCell2 / 1048576.0, 2).ToString() + "M");
					}
					else
					{
						this.listCell.get_Item(i).set_Text(Math.Round(totalStreamCell2 / 1024.0).ToString() + "KB");
					}
					if (totalStreamWifi2 >= 1048576u)
					{
						this.listWifi.get_Item(i).set_Text(Math.Round(totalStreamWifi2 / 1048576.0, 2).ToString() + "M");
					}
					else
					{
						this.listWifi.get_Item(i).set_Text(Math.Round(totalStreamWifi2 / 1024.0).ToString() + "KB");
					}
				}
				else
				{
					this.listDate.get_Item(i).set_Text(dateTime2.ToString("yyyy-MM-dd"));
					this.listCell.get_Item(i).set_Text("0KB");
					this.listWifi.get_Item(i).set_Text("0kB");
				}
			}
			goto IL_37F;
		}
		private void ShowYearLine(int index, int nYear)
		{
			this.YearLine.set_Margin(new Thickness(0.0, 53.0 + (double)index * 69.0, 0.0, 0.0));
			this.TxtYear.set_Text(nYear.ToString());
			this.YearLine.set_Visibility(0);
		}
		private ApplicationBar getApplicationBar()
		{
			if (this.mBar != null)
			{
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			if (this.mBar != null)
			{
				this.mBar.set_BackgroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_BK_BRUSH).get_Color());
				this.mBar.set_ForegroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_FG_BRUSH).get_Color());
			}
			this.clearHistoryButton = new ApplicationBarMenuItem(strings.Set_FlowControl_ClearArertTitle);
			this.clearHistoryButton.add_Click(new EventHandler(this.clearHistoryButton_Click));
			this.mBar.get_MenuItems().Add(this.clearHistoryButton);
			return this.mBar;
		}
		private void clearHistoryButton_Click(object sender, EventArgs e)
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Set_FlowControl_ClearArertTitle, strings.Set_FlowControl_ClearArertContent, true, strings.COM_Confirm, strings.COM_Cancel);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.OnClearBottleMsgHandler);
		}
		private void OnClearBottleMsgHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				FlowControl.cleanNetStream();
				this.RefreshUI();
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Setting/NetFlowPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.TxtTotalSum = (TextBlock)base.FindName("TxtTotalSum");
			this.Txt3G2GAll = (TextBlock)base.FindName("Txt3G2GAll");
			this.TxtWifiAll = (TextBlock)base.FindName("TxtWifiAll");
			this.stackPanel0 = (StackPanel)base.FindName("stackPanel0");
			this.TxtTimeData0 = (TextBlock)base.FindName("TxtTimeData0");
			this.Txt3G2GData0 = (TextBlock)base.FindName("Txt3G2GData0");
			this.TxtWifiData0 = (TextBlock)base.FindName("TxtWifiData0");
			this.stackPanel1 = (StackPanel)base.FindName("stackPanel1");
			this.TxtTimeData1 = (TextBlock)base.FindName("TxtTimeData1");
			this.Txt3G2GData1 = (TextBlock)base.FindName("Txt3G2GData1");
			this.TxtWifiData1 = (TextBlock)base.FindName("TxtWifiData1");
			this.stackPanel2 = (StackPanel)base.FindName("stackPanel2");
			this.TxtTimeData2 = (TextBlock)base.FindName("TxtTimeData2");
			this.Txt3G2GData2 = (TextBlock)base.FindName("Txt3G2GData2");
			this.TxtWifiData2 = (TextBlock)base.FindName("TxtWifiData2");
			this.stackPanel3 = (StackPanel)base.FindName("stackPanel3");
			this.TxtTimeData3 = (TextBlock)base.FindName("TxtTimeData3");
			this.Txt3G2GData3 = (TextBlock)base.FindName("Txt3G2GData3");
			this.TxtWifiData3 = (TextBlock)base.FindName("TxtWifiData3");
			this.stackPanel4 = (StackPanel)base.FindName("stackPanel4");
			this.TxtTimeData4 = (TextBlock)base.FindName("TxtTimeData4");
			this.Txt3G2GData4 = (TextBlock)base.FindName("Txt3G2GData4");
			this.TxtWifiData4 = (TextBlock)base.FindName("TxtWifiData4");
			this.stackPanel5 = (StackPanel)base.FindName("stackPanel5");
			this.TxtTimeData5 = (TextBlock)base.FindName("TxtTimeData5");
			this.Txt3G2GData5 = (TextBlock)base.FindName("Txt3G2GData5");
			this.TxtWifiData5 = (TextBlock)base.FindName("TxtWifiData5");
			this.stackPanel6 = (StackPanel)base.FindName("stackPanel6");
			this.TxtTimeData6 = (TextBlock)base.FindName("TxtTimeData6");
			this.Txt3G2GData6 = (TextBlock)base.FindName("Txt3G2GData6");
			this.TxtWifiData6 = (TextBlock)base.FindName("TxtWifiData6");
			this.YearLine = (StackPanel)base.FindName("YearLine");
			this.TxtYear = (TextBlock)base.FindName("TxtYear");
		}
	}
}
